﻿package com.zkingsoft.services.pc.impl;

import com.zkingsoft.services.pc.PcMenuCategoryService;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.model.pc.PcMenuCategory;
import com.zkingsoft.dao.pc.PcMenuCategoryDao;

import org.springframework.stereotype.Service;

import java.util.Map;

import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.util.ModelUtils;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-03-14 14:37
 */
@Service("pcMenuCategoryService")
public class  PcMenuCategoryServiceImpl implements    PcMenuCategoryService  {

	
	@Autowired
	private PcMenuCategoryDao pcMenuCategoryDao;
	
	
	@Override
	public int add(PcMenuCategory pcMenuCategory){
		
		return pcMenuCategoryDao.insert(pcMenuCategory);
		
	}
	
	@Override
	public int batchAdd(List<PcMenuCategory>  pcMenuCategoryList) {
		int num = 0;

		int c = 10000;
		int size = pcMenuCategoryList.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= pcMenuCategoryList.size() ? pcMenuCategoryList.size() : end;
			List<PcMenuCategory> insertList = pcMenuCategoryList.subList(begin, end);
			num += pcMenuCategoryDao.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(PcMenuCategory oldPcMenuCategory
	,PcMenuCategory newPcMenuCategory){
	
		if (!ModelUtils.isModified(oldPcMenuCategory, newPcMenuCategory)) {
			return 1;
		}
		Map<String, Object> modifyMap=null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldPcMenuCategory, newPcMenuCategory);
		} catch (Exception e) {
			throw new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("meuId", oldPcMenuCategory.getMeuId());
			pcMenuCategoryDao.updateByMap(modifyMap);
		}
		return 1;
	}
	
	@Override
	public int modifyByModel(PcMenuCategory pcMenuCategory){
	
		return pcMenuCategoryDao.updateByModel(pcMenuCategory);
	
	}
	
	
	
	@Override
	public int remove(List<Long> list){
		int i = 0;
		for (Long meuId : list) {
			removeById(meuId);
			i++;
		}
		return i;
	
	}
/**
 * 父集删除
 */
	@Override
	public int removeById(Long meuId){
		PcMenuCategory category = new PcMenuCategory();
		category.setMeuParentId(meuId);
		List<PcMenuCategory> list = pcMenuCategoryDao.selectByModel(category);
		for(PcMenuCategory  pmc : list){
			removeById(pmc.getMeuId());
		}
		return pcMenuCategoryDao.deleteById(meuId);
	
	}
	
	@Override
	public int removeByModel(PcMenuCategory pcMenuCategory){
	
		return pcMenuCategoryDao.deleteByModel(pcMenuCategory);
	
	}
	
	
	@Override
	public List<PcMenuCategory> findInPage(PcMenuCategory pcMenuCategory,  PaginationVO pageVo){
	
		return pcMenuCategoryDao.selectInPage(pcMenuCategory , pageVo);
	
	}
	
	@Override
	public List<PcMenuCategory> findByModel(PcMenuCategory pcMenuCategory){
	
		return pcMenuCategoryDao.selectByModel(pcMenuCategory);
	
	}
	
	@Override
	public int  findTotal(PcMenuCategory pcMenuCategory){
	
		return pcMenuCategoryDao.selectTotalRecord(pcMenuCategory);
	
	}
	
	@Override
	public PcMenuCategory  findById(Long meuId){
	
		return pcMenuCategoryDao.selectById(meuId);
	
	}

   	
	
	
}